package IL;

import java.util.ArrayList;
import java.util.List;
import ILTypes.ILClass;

public class ClassGenerator {
	
	public ILClass cls;
	public List<MethodGenerator> methodGeneratorList;
	
	public ClassGenerator() {
		methodGeneratorList = new ArrayList<MethodGenerator>();
	}

	public ClassGenerator(ILClass cls) {
		methodGeneratorList = new ArrayList<MethodGenerator>();
		this.cls = cls;
	}

	public List<String> prepareClassHeader()
	{
		List<String> classHeader = new ArrayList<String>();
		
		classHeader.add(".assembly extern mscorlib {}");
		classHeader.add("\n\n");
		classHeader.add(".assembly Methods {\n");
		classHeader.add("	.ver 1:0:0:1 \n");
		classHeader.add("}\n\n");
	
		return classHeader;
	}
	
	
	public List<String> prepareClassDeclarationString()
	{
		List<String> classHeader = new ArrayList<String>();
		StringBuffer classDeclString = new StringBuffer();
		StringBuffer extendString = new StringBuffer();
		StringBuffer implementString = new StringBuffer();
		
		classDeclString.append(".class");
		
		if(cls.isInterface)
			classDeclString.append(" interface");
		
		if(cls.isPublic)
			classDeclString.append(" public");
		else
			classDeclString.append(" private");
		
		if(cls.isAbstract || cls.isInterface)
			classDeclString.append(" abstract");
		
		classDeclString.append(" auto ansi");
		classDeclString.append(" " + cls.GetName());
		classHeader.add(classDeclString.toString());
		
		if(!(cls.isAbstract && cls.isInterface))
		{
			extendString.append("       extends");
			String superName = cls.GetSuperName();
			
			if(superName.equals("java/lang/Object"))
				extendString.append(" " + "[mscorlib]System.Object");
			else
				extendString.append(" " + superName);
		}

		classHeader.add(extendString.toString());

		String[] interfaces = cls.GetInterfaces();
		
		if(interfaces != null && interfaces.length > 0)
		{
			implementString.append("       implements");
			
			for(int i=0; i<interfaces.length; i++)
			{
				implementString.append("\n          " + interfaces[i]);
				if(i < (interfaces.length-1)) {
					implementString.append(",");
				}
			}
			classHeader.add(implementString.toString());
		}
	
		classHeader.add("\n{\n");
		return classHeader;
	}

	
	public List<String> prepareClassFooter()
	{
		List<String> classFooter = new ArrayList<String>();
		classFooter.add("}");
		classFooter.add("\n");
		return classFooter;
	}


}
